package com.ebelter.temperaturegun.model.app;


import android.text.TextUtils;

import com.ebelter.btcomlib.CommonLib;
import com.ebelter.btcomlib.utils.TimeUtils;
import com.ebelter.btcomlib.utils.UserSpUtil;
import com.ebelter.temperaturegun.R;
import com.ebelter.temperaturegun.TAppConfig;
import com.ebelter.temperaturegun.ui.activity.PeopleChooseActivity;

import static com.ebelter.btcomlib.bases.activity.BaseActivity.getString_;

//本app的工具
public class TemUtils {


    //获取登录的用户信息
    public static String getUerNickName(){return UserSpUtil.readString(IConstant.IUserSpCon.NICKNAME,null);}

    public static String getPsw(){return UserSpUtil.readString(IConstant.IUserSpCon.PSW,null);}

    //获取登录的用户邮箱
    public static String getUerEmail(){return UserSpUtil.readString(IConstant.IUserSpCon.EMAIL,null);}

    public static long getUerID(){return UserSpUtil.readLong(IConstant.IUserSpCon.USERID);}

    //获取登录的用户单位 0代表°C 1代表°F
    public static int getUerUnit(){
        return UserSpUtil.readInt(IConstant.IUserSpCon.UNIT,0);
    }

    //获取警告温度
    public static float getUerWarringUnit(){return UserSpUtil.readFloat(IConstant.IUserSpCon.WARRING_UNIT,37);}

//    //获取生日
//    public static String getBirthday(){return UserSpUtil.readString(IConstant.IUserSpCon.b);}

// <string name="piandi">偏低</string>
//    <string name="zhengchang">正常</string>
//    <string name="piangao">偏高</string>

    private static final long ONE_DAY = 24*3600*1000l;//一天的毫秒数
    public static String getResultDesc(float temperature){
        String birday;
        //UserSpUtil.writeString(IConstant.IUserSpCon.BIRTHDAY,resultData.birthday);//格式 1991-06-05
        if (TAppConfig.isVisitorModel){
            if (TextUtils.isEmpty(PeopleChooseActivity.VISITER_BIR)){
                PeopleChooseActivity.VISITER_BIR="1998-06-06";
            }
            birday= PeopleChooseActivity.VISITER_BIR.substring(0,10);
        }else {
            birday=UserSpUtil.readString(IConstant.IUserSpCon.BIRTHDAY);//格式 1991-06-05
        }
        long birthLong = TimeUtils.parseFormatter3Time(birday).getTime();
        long currentLong=System.currentTimeMillis();

        long chazhi=currentLong-birthLong;
        if (chazhi<0){
            chazhi=0;
        }
        int tianshu = (int) (chazhi/ONE_DAY);
        if (tianshu<=90){
            if (temperature<36.1f){
                return getString_(R.string.piandi);
            }else if (temperature>=36.1f&&temperature<37.6f){
                return getString_(R.string.zhengchang);
            }else{
                return getString_(R.string.piangao);
            }
        }else if (tianshu>90&&tianshu<=180){
            if (temperature<36.1f){
                return getString_(R.string.piandi);
            }else if (temperature>=36.1f&&temperature<37.9f){
                return getString_(R.string.zhengchang);
            }else{
                return getString_(R.string.piangao);
            }
        }else if (tianshu>180&&tianshu<=365){
            if (temperature<36.1f){
                return getString_(R.string.piandi);
            }else if (temperature>=36.1f&&temperature<37.5f){
                return getString_(R.string.zhengchang);
            }else{
                return getString_(R.string.piangao);
            }

        }else {
            if (temperature<36.1f){
                return getString_(R.string.piandi);
            }else if (temperature>=36.1f&&temperature<37.3f){
                return getString_(R.string.zhengchang);
            }else{
                return getString_(R.string.piangao);
            }
        }
    }


    public static int getResultDesc2(float temperature){
        String birday=UserSpUtil.readString(IConstant.IUserSpCon.BIRTHDAY);//格式 1991-06-05

        long birthLong = TimeUtils.parseFormatter3Time(birday).getTime();
        long currentLong=System.currentTimeMillis();

        long chazhi=currentLong-birthLong;
        if (chazhi<0){
            chazhi=0;
        }
        int tianshu = (int) (chazhi/ONE_DAY);
        if (tianshu<=90){
            if (temperature<36.1f){
                return 1;
            }else if (temperature>=36.1f&&temperature<37.6f){
                return 2;
            }else{
                return 3;
            }
        }else if (tianshu>90&&tianshu<=180){
            if (temperature<36.1f){
                return 1;
            }else if (temperature>=36.1f&&temperature<37.9f){
                return 2;
            }else{
                return 3;
            }
        }else if (tianshu>180&&tianshu<=365){
            if (temperature<36.1f){
                return 1;
            }else if (temperature>=36.1f&&temperature<37.5f){
                return 2;
            }else{
                return 3;
            }

        }else {
            if (temperature<36.1f){
                return 1;
            }else if (temperature>=36.1f&&temperature<37.3f){
                return 2;
            }else{
                return 3;
            }
        }
    }

}
